package com.hanklee.demo

import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectIndexed
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.transform

data class Person(val name: String, val age: Int) {
    fun sayHello() {
        println("Hello, my name is $name, I am $age years old.")
    }

    override fun equals(other: Any?): Boolean {
        return if (other is Person) {
            name == other.name && age == other.age
        } else {
            false
        }
    }
}


//suspend fun main() {
//    val p1 = Person("Alice", 20)
//    val p2 = Person("Bob", 25)
//    val p3 = Person("Alice", 20)
//    val p4 = Person("Alice", 20)
//
////    val flow = flowOf(p1, p2, p3, p4)
////    //flow 去重之后再收集
////    flow.distinctUntilChanged().collectIndexed { index, value ->
////        println("Collecting $index: ${value.name} ${value.age}")
////    }
////
////    flow.collect() {
////        println(it.name)
////    }
//
//    val flow = flowOf(1, 2, 3)
//
//    flow.transform() { value ->
//        emit(value * 2)
//        emit(value * 3)
//    }.collect { println(it) }
//
//
//}
